package fr.castorhoz.isi_connectivity_widget.WifiWidget;

import android.content.Context;
import android.content.IntentFilter;
import android.graphics.drawable.Drawable;
import android.net.wifi.WifiManager;
import fr.castorhoz.isi_connectivity_widget.ConnButton;
import fr.castorhoz.isi_connectivity_widget.R;


public class WifiButton extends ConnButton {

	

	public WifiButton(Context context) {
		// //RECEIVERS//////////////////////////////////////////////
		if (receiver == null)
			receiver = new WifiBroadcastReceiver(this);
		IntentFilter filter = new IntentFilter(WifiManager.WIFI_STATE_CHANGED_ACTION);
		context.getApplicationContext().registerReceiver(receiver, filter);
		////////////////////////////////////////////////////////////
	}

	@Override
	public void enableNetwork(Context context) {
		WifiManager mgr = getWifiManager(context);
		mgr.setWifiEnabled(true);
	}

	@Override
	public void disableNetwork(Context context) {
		WifiManager mgr = getWifiManager(context);
		mgr.setWifiEnabled(false);
	}

	private WifiManager getWifiManager(Context context) {
		return (WifiManager) context.getApplicationContext().getSystemService(
				Context.WIFI_SERVICE);
	}
	
	@Override
	public String getAction(){
		return "fr.imberle.connectivityWidget.CLICK_WIFI";
	}
	
	@Override
	public int getSelectorOff() {
		return R.drawable.wifi_selector_off;
	}
	
	@Override
	public int getSelectorOn() {
		return R.drawable.wifi_selector_on;
	}
	
	@Override
	public int getSelectorUnknown() {
		return R.drawable.wifi_selector_unknown;
	}


}
